import 'package:bruno/bruno.dart';
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'package:get/get_navigation/src/routes/transitions_type.dart';
import 'package:xiongmao_clean_flutter_module/res/colors.dart';
import 'package:xiongmao_clean_flutter_module/router/xm_router.dart';
import 'package:xiongmao_clean_flutter_module/util/brn_config_utils.dart';
import 'package:xiongmao_clean_flutter_module/util/device_utils.dart';

void main() async {
  //初始化 Flutter Boost 的路由
  CustomFlutterBoostBinding();

  await SpUtil.getInstance(); // 初始化 SpUtil
  await Device.initDeviceInfo(); // 初始化 SpUtil

  initRouters(); // 初始化 SpUtil

  //框架全局配置
  BrnInitializer.register(allThemeConfig: BrnConfigUtils.defaultAllConfig);

  //直接Run
  runApp(ScreenUtilInit(
    designSize: const Size(375, 667),
    builder: (context, child) {
      return GetMaterialApp(
        defaultTransition: Transition.noTransition,
        debugShowCheckedModeBanner: false,
        // 去除右上角debug的标签
        title: '熊猫清洁云',
        theme: ThemeData(
          primarySwatch: Colors.blue,
          colorScheme: ColorScheme.fromSwatch().copyWith(
            background: Colours.base_primary_bg_page, // 设置全局背景色为白色
          ),
        ),
        home: const MyApp(),
        builder: FlutterSmartDialog.init(),
      );
    },
  ));
}


///创建一个自定义的Binding，继承和with的关系如下，里面什么都不用写
class CustomFlutterBoostBinding extends WidgetsFlutterBinding with BoostFlutterBinding {}

class MyApp extends StatefulWidget {
  const MyApp();

  @override
  State<StatefulWidget> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    print('flutter initState was called');
  }

  @override
  Widget build(BuildContext context) {
    return FlutterBoostApp(routeFactory, appBuilder: appBuilder);
  }
}
